package disjunction.examples.basics
{
	import disjunction.core.View;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Shape;
	
	/**
	 *
	 *
	 * @author Nick Wiggill
	 */
	
	public class DemoView extends View
	{
		private var _sprite:Shape;
		
		/** 
		 * Prepare a graphics object to use graphics.copyFrom on when creating a new
		 * DisplayObjectEntityView.
		 */
		public function initialise(data:Object):void
		{
			var context:DisplayObjectContainer = data as DisplayObjectContainer;
			
			_sprite = new Shape();
			
			//face
			_sprite.graphics.beginFill(0xFFFF00);
			_sprite.graphics.drawCircle(0, 0, 1);
			_sprite.graphics.endFill();
			
			//left eye
			_sprite.graphics.beginFill(0x000000);
			_sprite.graphics.drawCircle(-.5, -.4, .3);
			_sprite.graphics.endFill();
			
			//right eye
			_sprite.graphics.beginFill(0x000000);
			_sprite.graphics.drawCircle(.5, -.4, .3);
			_sprite.graphics.endFill();
			
			//mouth
			_sprite.graphics.beginFill(0x000000);
			//_sprite.graphics.lineStyle(1);
			_sprite.graphics.moveTo(.6, .4);
			_sprite.graphics.lineTo(0, .6);
			_sprite.graphics.lineTo(-.6, .4);
			_sprite.graphics.lineTo(.6, .4);
			_sprite.graphics.endFill();
			
			//scale up
			_sprite.scaleX = _sprite.scaleY = model.radius;
			
			//add to display
			context.addChild(_sprite);
		}
		
		public override function update(timeDeltaMs:uint):void
		{
			_sprite.x = model.position.x;
			_sprite.y = model.position.y;
		}
	}
}